<template>
  <Back title="修改密码">
    <div class="box">
      <div class="pass">修改密码</div>
      <div class="confirm">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="新密码*" prop="pass" style="font-size: 10px;">
            <el-input type="password" v-model="ruleForm.pass" autocomplete="off" style="width: 275px;"></el-input>
          </el-form-item>
          <el-form-item label="确认密码*" prop="checkPass">
            <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off" style="width: 275px; "></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>

          </el-form-item>
        </el-form>
      </div>
    </div>
  </Back>
</template> 
<script>
import Back from '@/components/Part/BackColor.vue'
export default {
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('年龄不能为空'));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error('请输入数字值'));
        } else {
          callback();
        }

      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: '',
        checkPass: '',
        age: ''
      },
      rules: {
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        checkPass: [
          { validator: validatePass2, trigger: 'blur' }
        ],
        age: [
          { validator: checkAge, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          localStorage.removeItem('token')
          localStorage.removeItem('adminname')
          localStorage.removeItem('loginState')
          //  this.$store.commit('changeLoginState',false)
          this.$router.push({ path: '/' })
          // alert('submit!');

        } else {
          return false;
        }
      });

    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  components: {
    Back,
  }
}
</script>
  
<style scoped>
.bule {
  vertical-align: 3px;
  display: inline-block;
  width: 20px;
  height: 10px;
  border-radius: 999px;
  background: #006EFF;
  margin-right: 8px;
}

.content {
  width: 1280px;
  min-height: 333px;

}

.first {
  font-size: 20px;
  padding-top: 13px;
  padding-bottom: 22px;

}

.box {
  width: 100%;
  height: 274px;
  /* border: 1px solid #ccc; */
  border-radius: 5px;
  /* background-color: aqua; */
}

.pass {
  height: 40px;
  font-size: 10px;
  color: #006EFF;
  line-height: 40px;
  box-sizing: border-box;
  padding-left: 15px;
  background-color: rgba(242, 242, 242, 1);
  color: bl;
}

.confirm {
  box-sizing: border-box;
  padding-top: 10px;
}
</style>